public class HanoiTower {
    public static void move(char d1,char d2) {
        System.out.print(d1+"->"+d2+"  ");
    }
    //n为盘子个数，p1为起始，p2为中途，p3为目标
    public static void hanoi(int n,char p1,char p2,char p3) {
        if(n == 1) {
            move(p1,p3);
        }else {
            hanoi(n-1,p1,p3,p2);//a上方n-1个盘子通过c来移动到b上
            move(p1,p3);
            hanoi(n-1,p2,p1,p3);//b上方n-1个盘子再通过a来移动到c上
        }
    }
    public static void main(String[] args) {
        hanoi(1,'A','B','C');
        System.out.println();
        hanoi(2,'A','B','C');
        System.out.println();
        hanoi(3,'A','B','C');
        System.out.println();
        hanoi(4,'A','B','C');
    }

}
